package net.jarang.study.spring.web;

import java.nio.charset.Charset;

import net.jarang.study.spring.converter.Level;
import net.jarang.study.spring.converter.LevelPropertyEditor;

import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class ValidationController2 {	
	
	@RequestMapping("/charset2")
	public ModelAndView charset2(@RequestParam Charset charset, Errors errors) {
		ModelAndView mav = new ModelAndView("result");
		mav.addObject("result1", charset);
		return mav;
	}

	@RequestMapping("/level2")
	public ModelAndView level2(@RequestParam Level level) {
		ModelAndView mav = new ModelAndView("result");
		mav.addObject("result1", level);
		return mav;
	}
	
	@InitBinder
	public void initBinder(WebDataBinder dataBinder) {
		dataBinder.registerCustomEditor(Level.class, new LevelPropertyEditor());
	}	
}
